package com.sheep.jucdemo.part9.part9_3;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Date 2022/5/22 21:42
 * @Created by sheep
 */
public class Test9_3_1 {

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        System.out.println("当前系统时间" + start);
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(5);

        executor.schedule(new Runnable() {
            @Override
            public void run() {
                long end = System.currentTimeMillis();
                System.out.println("开始执行时间" + end);
                System.out.println("时间间隔" + (end - start));
            }
        }, 2, TimeUnit.SECONDS);
        // 上面代码执行一次就结束，所以通常schedule方法后加shutdown方法
        executor.shutdown();
    }
}
